package com.bawei.mdm2207alast

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.bawei.mdm2207alast.apps.LocalAppsPage
import com.bawei.mdm2207alast.apps.OnLineAppsPage
import com.bawei.mdm2207alast.file.LocalFilesPage
import com.bawei.mdm2207alast.file.OnLineFilesPage
import com.bawei.mdm2207alast.mine.ask.AskApproveListPage
import com.bawei.mdm2207alast.mine.ask.AskApprovePage
import com.bawei.mdm2207alast.mine.ask.AskCommitPage
import com.bawei.mdm2207alast.mine.ask.AskDetailPage
import com.bawei.mdm2207alast.mine.ask.AskListPage
import com.bawei.mdm2207alast.mine.user.LoginPage
import com.bawei.mdm2207alast.mine.user.RegisterPage
import com.bawei.mdm2207alast.report.AddReportPage
import com.bawei.mdm2207alast.route.RouteConfig
import com.bawei.mdm2207alast.sign.SelSignPage
import com.bawei.mdm2207alast.view.MainPage
import com.bawei.mdm2207alast.view.WelcomePage
import com.bawei.mdm2207alast.report.SelReportPage
import com.bawei.mdm2207alast.sign.InsertSignPage
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    @SuppressLint("CoroutineCreationDuringComposition")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        // 混合开发，在xml布局中使用Compose
        /*setContentView(R.layout.activity_main)

        findViewById<ComposeView>(R.id.compose_view).setContent {
            MainPage()
        }
        findViewById<ComposeView>(R.id.compose_view1).setContent {
            MainPage()
        }
        findViewById<ComposeView>(R.id.compose_view2).setContent {
            MainPage()
        }*/

        setContent {

            // 导航控制器
            val navController = rememberNavController()

            // 启动协程-延迟3秒钟 进入主页面
            lifecycleScope.launch {
                delay(3000)

                navController.navigate(RouteConfig.MAIN)
            }

            NavHost(
                navController = navController,
                startDestination = RouteConfig.WELCOME
            ) {
                composable(RouteConfig.WELCOME) {
                    WelcomePage(navController)
                }
                composable(RouteConfig.MAIN) {
                    MainPage(navController)
                }
                composable(RouteConfig.ONLINEAPPS) {
                    OnLineAppsPage(navController)
                }
                composable(RouteConfig.LOCALAPPS) {
                    LocalAppsPage(navController)
                }
                composable(RouteConfig.ONLINEFILES) {
                    OnLineFilesPage(navController)
                }
                composable(RouteConfig.SELREPORT) {
                    SelReportPage(navController)
                }
                composable(RouteConfig.SELSIGN) {
                    SelSignPage(navController)
                }
                composable(RouteConfig.LOCAL_FILE) {
                    LocalFilesPage(navController)
                }
                composable(RouteConfig.ADD_REPORT + "/{json}") {
                    val json = it.arguments?.getString("json").toString()
                    AddReportPage(navController, json = json)
                }
                composable(RouteConfig.INSERT_SIGN) {
                    InsertSignPage(navController)
                }
                composable(RouteConfig.LOGIN) {
                    LoginPage(navController)
                }
                composable(RouteConfig.REGISTER) {
                    RegisterPage(navController)
                }
                composable(RouteConfig.ASK_LIST_PAGE) {
                    AskListPage(navController)
                }
                composable(RouteConfig.ASK_COMMIT_PAGE) {
                    AskCommitPage(navController)
                }
                composable(RouteConfig.ASK_DETAIL + "/{json}") {
                    val json = it.arguments?.getString("json").toString()
                    AskDetailPage(navController, json)
                }
                composable(RouteConfig.ASK_APPROVE_LIST) {
                    AskApproveListPage(navController)
                }
                composable(RouteConfig.ASK_APPROVE + "/{json}") {
                    val json = it.arguments?.getString("json").toString()
                    AskApprovePage(navController, json)
                }
            }
        }
    }
}